<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>


<html>
  <head>
    <base href="${pageContext.request.contextPath}/">
    <title>订单信息管理</title>
    <%@ include file="../common/base.jsp" %>
   
    <script type="text/javascript">
        
    </script>

  </head>
  
  <body>
  	<!--head-->
	<div id="head">
		<jsp:include page="../common/head.jsp"></jsp:include>
	</div>
	<!--head end-->
	<!--container-->
	<div id="container">
		<div id="pageId" style="display: none;">02-06-01</div>
		<!--sidebar-->
		<jsp:include page="../common/menu.jsp"></jsp:include>
	    <!--sidebar-->
	    <!--main-->
	    <div class="main">
			<div class="location" style="background-position:22px -109px;">
				平台管理<span>&gt;</span>订单管理<span>&gt;</span>订单信息管理<span>&gt;</span>订单详情
			</div>
	        <!--content-->
			<div class="content">
				<h2 class="tit_blue">订单详细信息</h2>
				<table class="table_type1 tablesorter" id="partnerInfo">
					<tr>
						<th style="width: 20%">订单ID</th>
						<td >${orderMap.id }</td>
					</tr>
					<tr>
						<th>订单金额</th>
						<td>${orderMap.orderMoney }</td>
					</tr>
					<tr>
						<th>订单所属产品名称</th>
						<td>${orderMap.productName }</td>
					</tr>
					<tr>
						<th>下单用户名称</th>
						<td>${orderMap.nickName }</td>
					</tr>
					<tr>
						<th>订单状态</th>
						<td>${orderMap.orderName }</td>
					</tr>
					<tr>
						<th>身份证正面照</th>
						<td>
							<img src="../../static${orderSupplyMap.cardFrontImage}" style="width:420px;height: 240px">
							<input type = "hidden" id="orderId" value="${orderMap.id}">
							<input type = "hidden" id="supplyDateId" value="${supplyDateId}">
							</br>身份证姓名：<input id="cardName" name="cardName" value="${carData.cardName}"></br>
							身份证性别：<select id="cardSex" name="cardSex">
								<option value="0" <c:if test="${carData.cardSex == 0}"> selected</c:if>>男</option>
								<option value="1" <c:if test="${carData.cardSex == 1}"> selected</c:if>>女</option>
							</select></br>
							身份证生日：<input id="cardBirthday" name="cardBirthday" value="${carData.cardBirthday}"></br>
							身份证民族：<input id="cardNation" name="cardNation" value="${carData.cardNation}"></br>
							身份证编号：<input id="cardNo" name="cardNo" value="${carData.cardNo}"></br>
							身份证地址：<input id="cardAddress" name="cardAddress" value="${carData.cardAddress}"></br>
						</td>
					</tr>
					<tr>
						<th>身份证反面照</th>
						<td><img src="http://localhost:9091/${orderSupplyMap.cardBackImage}" style="width:420px;height: 240px">
							</br>身份证生效时间：<input id="cardIssueTime" name="cardIssueTime" value="${carData.cardIssueTime}"></br>
							身份证失效时间：<input id="cardInvalidTime" name="cardInvalidTime" value="${carData.cardInvalidTime}">
						</td>
					</tr>
					<tr>
						<th>行驶证照片</th>
						<td><img src="http://localhost:9091/${orderSupplyMap.vehicleLicenseImage}" style="width:420px;height: 240px">
							</br>行驶证品牌型号：<input id="vehicleModel" name="vehicleModel" value="${carData.vehicleModel}"></br>
							行驶证发证日期：<input id="vehicleIssueTime" name="vehicleIssueTime" value="${carData.vehicleIssueTime}"></br>
							行驶证使用性质：<input id="vehicleUse" name="vehicleUse" value="${carData.vehicleUse}"></br>
							行驶证发动机号码：<input id="vehicleEngineNo" name="vehicleEngineNo" value="${carData.vehicleEngineNo}"></br>
							行驶证号牌号码：<input id="vehiclePlate" name="vehiclePlate" value="${carData.vehiclePlate}"></br>
							行驶证所有人：<input id="vehicleUserName" name="vehicleUserName" value="${carData.vehicleUserName}"></br>
							行驶证住址：<input id="vehicleAddress" name="vehicleAddress" value="${carData.vehicleAddress}"></br>
							行驶证注册日期：<input id="vehicleRegisterTime" name="vehicleRegisterTime" value="${carData.vehicleRegisterTime}"></br>
							行驶证车辆识别代号：<input id="vehicleType" name="vehicleType" value="${carData.vehicleType}"></br>
							行驶证车辆类型：<input id="vehicleIdentificationNumber" name="vehicleIdentificationNumber" value="${carData.cardIssueTime}">
						</td>
					</tr>
					<tr>
						<th>驾驶证照片</th>
						<td><img src="http://localhost:9091/${orderSupplyMap.drivingLicenseImage}" style="width:420px;height: 240px">
							</br>驾驶证证号：<input id="driveNo" name="driveNo" value="${carData.driveNo}"></br>
							驾驶证有效期限：<input id="driveExpirationdate" name="driveExpirationdate" value="${carData.driveExpirationdate}"></br>
							驾驶证准驾车型：<input id="driveCarType" name="driveCarType" value="${carData.driveCarType}"></br>
							驾驶证有效起始日期：<input id="driveIssueTime" name="driveIssueTime" value="${carData.driveIssueTime}"></br>
							驾驶证住址：<input id="driveAddress" name="driveAddress" value="${carData.driveAddress}"></br>
							驾驶证姓名：<input id="driveUserName" name="driveUserName" value="${carData.driveUserName}"></br>
							驾驶证国籍：<input id="driveNationality" name="driveNationality" value="${carData.driveNationality}"></br>
							驾驶证出生日期：<input id="driveBirthday" name="driveBirthday" value="${carData.driveBirthday}"></br>
							驾驶证性别：<select id="driveSex" name="driveSex">
								<option value="0" <c:if test="${carData.driveSex == 0}"> selected</c:if>>男</option>
								<option value="1" <c:if test="${carData.driveSex == 1}"> selected</c:if>>女</option>
							</select></br>
							驾驶证初次领证日期：<input id="driveIssuedate" name="driveIssuedate" value="${carData.driveIssuedate}">
						</td>
					</tr>

					<c:if test="${orderMap.orderState == 4}">
						<tr>
							<th>审核状态</th>
							<td>
								<input type="radio" name="radioState" value="5" checked onchange="radioChange(5,4)">审核通过
								<input type="radio" name="radioState" value="6" onchange="radioChange(6,4)">驳回
							</td>
						</tr>

						<tr id="orDescTr" style="display: none;">
							<th>驳回原因</th>
							<td>
								<textarea id="orderRejectDesc" name="orderRejectDesc" style="width: 520px; height: 100px;"></textarea>
							</td>
						</tr>
					</c:if>

					<c:if test="${orderMap.orderState == 6}">
						<tr>
							<th>是否已退款</th>
							<td>
								<input type="radio" name="radioState" value="6" checked  onchange="radioChange(6,6)">否
								<input type="radio" name="radioState" value="7"  onchange="radioChange(7,6)">是
							</td>
						</tr>

						<tr id="refundDescTr" style="display: none;">
							<th>退款描述信息</th>
							<td>
								<textarea id="orderRefundDesc" name="orderDesc" style="width: 520px; height: 100px;"></textarea>
							</td>
						</tr>
					</c:if>
				</table>


				<div class="button_wrap">
					<a href="javascript:void(0);" onClick="saveInfo();"  class="bg_green">保存</a>
					<c:if test="${orderMap.orderState == 4}">
						<a href="javascript:void(0);" onClick="examineSaveInfo();"  class="bg_green">审核</a>
					</c:if>
					<c:if test="${orderMap.orderState == 6}">
						<a href="javascript:void(0);" onClick="orderRefund();"  class="bg_green">退款</a>
					</c:if>
					<input type="button" value="关闭" onclick="closeOrderDetail()" >
				</div>

			</div>
	        <!--content-->
		        <!--foot-->
			<%@ include file="../common/foot.jsp" %>
		        <!--foot-->
		    </div>
		</div>
	    <!--main-->
	</div>
	<!--container-->
	<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
	<script type="text/javascript">
		function radioChange(radioVal,orderState){
		    if(orderState == 4) {
                if (radioVal == 5) {
                    $("#orDescTr").hide();
                    $("#orderRejectDesc").text("");
                }

                if (radioVal == 6) {
                    $("#orDescTr").show();
                }
            }

            if(orderState == 6) {
                if (radioVal == 7) {
                    $("#refundDescTr").show();
                    $("#orderRefundDesc").text("");
                }

                if (radioVal == 6) {
                    $("#refundDescTr").hide();
                    $("#orderRefundDesc").text("");
                }
            }
		}

		function closeOrderDetail(){
            window.location.href = "${pageContext.request.contextPath}/order/showOrder";
		}

        //获取form表单所有参数
        function getParams(){
            var json = {};
            $(".content input,.content select").each(function(i,e){
                json[$(e).attr("id")] = $(e).attr("value");
            });
            return json;
        }

        //examineOrderSupplyDate
        function examineSaveInfo(){
            var orderRejectDesc = $("#orderRejectDesc").val();
			var orderState = $("input[name='radioState']:checked").val();
            $.ajax({
                type: "POST",
                url: "${pageContext.request.contextPath}/order/examineOrderSupplyDate",
                dataType:"json",
                data: {
                    "dataJson":JSON.stringify(getParams()),
					"orderState":orderState,
					"orderDesc":orderRejectDesc
                },
                success: function(data){
                    if (data.errorCode==0) {
                        prompt.alert("审核通过，已生成用户保单！");

                        setTimeout(function(){
                            window.location.href = "${pageContext.request.contextPath}/order/showOrder";
						},2000);
                    }else{
                        prompt.alert(data.msg);
                    }
                }
            });

		}

        function orderRefund(){

            var orderRefundDesc = $("#orderRefundDesc").val();
            var orderState = $("input[name='radioState']:checked").val();
            $.ajax({
                type: "POST",
                url: "${pageContext.request.contextPath}/order/updateOrderState",
                dataType:"json",
                data: {
                    "id":$("#orderId").val(),
                    "orderState":orderState,
                    "orderContent":orderRefundDesc
                },
                success: function(data){
                    if (data.errorCode==0) {
                        prompt.alert("线下退款已成功，订单关闭！");
                        setTimeout(function(){
                            window.location.href = "${pageContext.request.contextPath}/order/showOrder";
                        },2000);
                    }else{
                        prompt.alert(data.msg);
                    }
                }
            });

        }



		function saveInfo(){
            $.ajax({
                type: "POST",
                url: "${pageContext.request.contextPath}/order/saveOrderSupplyDate",
                dataType:"json",
                data: getParams(),
                success: function(data){
                    if (data.errorCode==0) {
                        prompt.alert("保存身份证、行驶证、驾驶证信息成功！");
                    }
                }
            });

		}



		function ocrImageAnalysi(path,fileType){
            $.ajax({
                type: "POST",
                url: "${pageContext.request.contextPath}/order/orderSupplyImage",
                dataType:"json",
                data: {
                    fileUrl:path,
                    fileType:fileType
                },
                success: function(data){
                    if (data.code==0) {
                        var json = eval(data.json);
                        if(fileType == "1"){
                            cardNoFront(json);
                        }else if(fileType == "2"){
                            cardNoBack(json);
                        }else if(fileType == "3"){
                            vehicle(json);
                        }else if(fileType == "4"){
                            drive(json)
                        }
                    }
                }
            });
        }
        function cardNoFront(json){
		    $("#cardName").val(json.cardName);
            $("#cardSex").val(json.cardSex);
            $("#cardBirthday").val(json.cardBirthday);
            $("#cardNation").val(json.cardNation);
            $("#cardNo").val(json.cardNo);
            $("#cardAddress").val(json.cardAddress);
		}

        function cardNoBack(json){
            $("#cardIssueTime").val(json.cardIssueTime);
            $("#cardInvalidTime").val(json.cardInvalidTime);
        }

        function drive(json){
            $("#driveNo").val(json.driveNo);
            $("#driveExpirationdate").val(json.driveExpirationDate);
            $("#driveCarType").val(json.driveCarType);
            $("#driveIssueTime").val(json.driveIssueTime);
            $("#driveAddress").val(json.driveAddress);
            $("#driveUserName").val(json.driveUserName);
            $("#driveNationality").val(json.driveNationality);
            $("#driveBirthday").val(json.driveBirthday);
            $("#driveSex").val(json.driveSex);
            $("#driveIssuedate").val(json.driveIssueDate);
		}

		function vehicle(json){
            $("#vehicleModel").val(json.vehicleModel);
            $("#vehicleIssueTime").val(json.vehicleIssueTime);
            $("#vehicleUse").val(json.vehicleUse);
            $("#vehicleEngineNo").val(json.vehicleEngineNo);
            $("#vehiclePlate").val(json.vehiclePlate);
            $("#vehicleUserName").val(json.vehicleUserName);
            $("#vehicleAddress").val(json.vehicleAddress);
            $("#vehicleRegisterTime").val(json.vehicleRegisterTime);
            $("#vehicleType").val(json.vehicleType);
            $("#vehicleIdentificationNumber").val(json.vehicleIdentificationNumber);
		}

        $(document).ready(function(e) {
            var supplyDateId = ${supplyDateId};
            if(supplyDateId == null || supplyDateId == 0) {
                setTimeout(ocrImageAnalysi("/upload/user/201709071821430001/cc.png", 1), 1000);
                setTimeout(ocrImageAnalysi("/upload/user/201709071821430001/dd.png", 2), 1000);
                setTimeout(ocrImageAnalysi("/upload/user/201709071821430001/aa.jpg", 3), 1000);
                setTimeout(ocrImageAnalysi("/upload/user/201709071821430001/bb.jpg", 4), 1000);
            }
        });

	</script>
  </body>
</html>
